<?php
namespace app\api\controller\v1;
use app\api\controller\Common;

class Zans extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("Zans");
	}
	public function add(){
		$this->postData['userid'] = $this->uinfo['id'];
		$result = $this->validate($this->postData, 'Zans.check_contentid');
		if ($result !== true) {
			return $this->app_error($result);
		}

		$id = $this->modelDb->save_data($this->postData);
		if ($id) {
			$model = $this->postData['typeid'] == 1 ? model("Member") : model("Requires");
			$model->where('id', $this->postData['contentid'])->setInc('zans');
			$zans = $model->where('id', $this->postData['contentid'])->value('zans');
			return $this->app_success(['zans'=>$zans]);
		}else{
			return $this->app_error($this->modelDb->getError());
		}
	}
}